package studentmanager;

import java.awt.Component;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import structure.Student;

public class GUIStudentCellEditor extends AbstractCellEditor implements TableCellRenderer{
	
	private static final long serialVersionUID = 1L;
	private  GUIStudentCell renderer;
	
	public GUIStudentCellEditor(){
		renderer = new GUIStudentCell();
	}
	
	@Override
	public Object getCellEditorValue() {
		return renderer.getStudent();
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		renderer.setSelected(isSelected);
		renderer.setStudent((Student)value);
		int rowHeight = renderer.getPreferredSize().height;
		table.setRowHeight(row, rowHeight);
		return renderer;
		
	}
}
